<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>新建一个 MySQL 数据库</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysql-create-db" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysql_create_db</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_create_db</span> &mdash; <span class="dc-title">新建一个 MySQL 数据库</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.mysql-create-db-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mysql_create_db</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$database name</code></span>
   [, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code></span>
  ] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>mysql_create_db()</strong></span> 尝试在指定的连接标识所关联的服务器上建立一个新数据库。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.mysql-create-db-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">database_name</code></dt>

     <dd>

      <p class="para">
       要创建的数据库名。
      </p>
     </dd>

    
    <dt>
<code class="parameter">
link_identifier</code></dt>
<dd>
<p class="para">MySQL
连接。如不指定连接标识，则使用由 <span class="function"><a href="mysql_connect.html" class="function">mysql_connect()</a></span>
最近打开的连接。如果没有找到该连接，会尝试不带参数调用
<span class="function"><a href="mysql_connect.html" class="function">mysql_connect()</a></span>
来创建。如没有找到连接或无法建立连接，则会生成
<strong><code>E_WARNING</code></strong> 级别的错误。</p></dd>


   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-create-db-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysql-create-db-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2123">
    <p><strong>Example #1 替代 <span class="function"><strong>mysql_create_db()</strong></span> 的例子</strong></p>
    <div class="example-contents"><p>
     <span class="function"><strong>mysql_create_db()</strong></span> 函数已废弃。最好用
     <span class="function"><a href="mysql_query.html" class="function">mysql_query()</a></span> 来提交一条 SQL 的
     <em>CREATE DATABASE</em> 语句来代替。
    </p></div>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_user'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_password'</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Could&nbsp;not&nbsp;connect:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br />}<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'CREATE&nbsp;DATABASE&nbsp;my_db'</span><span style="color: #007700">;<br />if&nbsp;(</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Database&nbsp;my_db&nbsp;created&nbsp;successfully\n"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Error&nbsp;creating&nbsp;database:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Database my_db created successfully
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-create-db-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">本扩展自 PHP 5.5.0
起已废弃，并在自 PHP 7.0.0 开始被移除。应使用 <a href="book.mysqli.html" class="link">MySQLi</a>
或 <a href="ref.pdo_mysql.html" class="link">PDO_MySQL</a> 扩展来替换之。参见
<a href="mysqlinfo.api.choosing.html" class="link">MySQL：选择 API</a> 指南以及<a href="faq.databases.html#faq.databases.mysql.deprecated" class="link">相关 FAQ</a> 来获取更多信息。用以替代本函数的有：</p>
   <p class="para">
    <ul class="simplelist">
     <li class="member"><span class="function"><a href="mysqli.query.html" class="function">mysqli_query()</a></span></li>
     <li class="member"><span class="methodname"><a href="pdo.query.html" class="methodname">PDO::query()</a></span></li>
    </ul>
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    为了向下兼容，可以使用下列已废弃的别名：
    <span class="function"><strong>mysql_createdb()</strong></span>
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    如果 MySQL 扩展是基于 MySQL 4.x 客户端库编译的话则本函数不可用。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysql-create-db-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mysql_query.html" class="function" rel="rdfs-seeAlso">mysql_query()</a> - 发送一条 MySQL 查询</span></li>
    <li class="member"><span class="function"><a href="mysql_select_db.html" class="function" rel="rdfs-seeAlso">mysql_select_db()</a> - 选择 MySQL 数据库</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>